package work.xiaohong.gupiao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.pojo.JijinFreeNumber;
import work.xiaohong.gupiao.service.JijinFreeNumberService;
import entity.Result;
import entity.StatusCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "JijinFreeNumber接口文档")
@RestController
@RequestMapping("/jijinFreeNumber")
//@CrossOrigin
public class JijinFreeNumberController {

    @Autowired
    private JijinFreeNumberService jijinFreeNumberService;

    /***
     * 分页条件搜索实现JijinFreeNumber
     * @param jijinFreeNumber
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "条件分页查询JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@RequestBody(required = false) @Parameter(name = "JijinFreeNumber对象",required = true) JijinFreeNumber jijinFreeNumber, @PathVariable int page, @PathVariable  int size){
        //调用JijinFreeNumberService实现分页条件查询JijinFreeNumber
        Page pageInfo = jijinFreeNumberService.findPage(jijinFreeNumber, page, size);
        return new Result<Page>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 分页搜索实现JijinFreeNumber
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @Operation(summary = "分页查询JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用JijinFreeNumberService实现分页查询JijinFreeNumber
        Page pageInfo = jijinFreeNumberService.findPage(page, size);
        return new Result<Page>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索JijinFreeNumber数据
     * @param jijinFreeNumber
     * @return
     */
    @Operation(summary = "多条件查询JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping(value = "/search" )
    public Result<List<JijinFreeNumber>> findList(@RequestBody(required = false) @Parameter(name = "JijinFreeNumber对象",required = true) JijinFreeNumber jijinFreeNumber){
        //调用JijinFreeNumberService实现条件查询JijinFreeNumber
        List<JijinFreeNumber> list = jijinFreeNumberService.findList(jijinFreeNumber);
        return new Result<List<JijinFreeNumber>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据Id删除jijinFreeNumber数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID删除JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "删除对象ID", required = true)
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用JijinFreeNumberService实现根据ID删除
        jijinFreeNumberService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 根据ID修改JijinFreeNumber数据
     * @param jijinFreeNumber
     * @param id
     * @return
     */
    @Operation(summary = "根据ID修改JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "修改对象ID", required = true)
    @PutMapping(value = "/{id}" )
    public Result update(@RequestBody @Parameter(name = "JijinFreeNumber对象",required = true) JijinFreeNumber jijinFreeNumber, @PathVariable Integer id){
        // 补充id
        jijinFreeNumber.setId(id);
        //调用JijinFreeNumberService实现修改JijinFreeNumber
        jijinFreeNumberService.update(jijinFreeNumber);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增JijinFreeNumber数据
     * @param jijinFreeNumber
     * @return
     */
    @Operation(summary = "添加JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping
    public Result add(@RequestBody  @Parameter(name = "JijinFreeNumber对象",required = true) JijinFreeNumber jijinFreeNumber){
        //调用JijinFreeNumberService实现添加JijinFreeNumber
        jijinFreeNumberService.add(jijinFreeNumber);
        return new Result(true, StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询JijinFreeNumber数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID查询JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "查询对象ID", required = true)
    @GetMapping("/{id}")
    public Result<JijinFreeNumber> findById(@PathVariable Integer id){
        //调用JijinFreeNumberService实现根据ID查询JijinFreeNumber
        JijinFreeNumber jijinFreeNumber = jijinFreeNumberService.findById(id);
        return new Result<JijinFreeNumber>(true,StatusCode.OK,"查询成功",jijinFreeNumber);
    }

    /***
     * 查询JijinFreeNumber全部数据
     * @return
     */
    @Operation(summary = "查询所有JijinFreeNumber",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping
    public Result<List<JijinFreeNumber>> findAll(){
        //调用JijinFreeNumberService实现查询所有JijinFreeNumber
        List<JijinFreeNumber> list = jijinFreeNumberService.findAll();
        return new Result<List<JijinFreeNumber>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
